// pages/item/detail/detail.js

var networkTool = require("../../../utils/networkTool.js");
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    itemdetail: {},
    similarData:[],
    regoodsData:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var code = (options.code);
    var data =  wx.getStorageSync("key");
    if(data)
    {
      console.log(data);
      var content = data.VIPCONTENT; 
      this.setData({
        itemdetail: content
      });
    }else{
    networkTool.itemDetails("007400040F810000", this.bindData); 
    }
    networkTool.itemSimilar("007400040F810000", this.bindSimilarData);
    networkTool.itemRegoods("007400040F810000", this.bindRegoodsData);
  },
  bindRegoodsData: function (data) {
    console.log(data);
    var content = data.VIPCONTENT;
    this.setData({
      regoodsData: content
    });
  },
  bindSimilarData: function (data) { 
    var content = data.VIPCONTENT;
    this.setData({
      similarData: content
    });
  },
  bindData: function (data) { 
    wx.setStorageSync("key", data);
    var content = data.VIPCONTENT;
    this.setData({
      itemdetail: content
    });
  },
  /**
   * 打开位置地图
   */
  openMapTap: function (event) {
    var map = (event.currentTarget.dataset.map);
    var name = (event.currentTarget.dataset.name);
    var address = (event.currentTarget.dataset.address);
    if (map && map.length > 0) {
      var mapxy = map.split(',');
      //console.log(mapxy[0] + "|" + mapxy[1]);
      if (mapxy.length == 2) {
        wx.getLocation({
          type: 'gcj02', //返回可以用于wx.openLocation的经纬度
          success: function (res) {
            var latitude = parseFloat(mapxy[1]);
            var longitude = parseFloat(mapxy[0]);
            wx.openLocation({
              latitude: latitude,
              longitude: longitude,
              scale: 28,
              name: name,
              address: address
            })
          }
        })
      }
    }
  },
  callTap: function (event) {
    var tel = (event.currentTarget.dataset.tel);
    wx.makePhoneCall({
      phoneNumber: tel //仅为示例，并非真实的电话号码
    })
  },
  shardTap:function(event){
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})